from mako.template import Template

from yacf.Tools.SourceStorage import FileType

class Template_FileType(FileType):
    """ Represents a file which contains a template 
        that it could be convert into a simple text.
    """
    def __init__(self):
        FileType.__init__(self, 'Template', '.tmpl')
            
    def pretty_print(self, text):
        """ Return a pretty representation of the file 
        
            :param text: The original text to be pretty printed
        """
        return text
    
    def render (self, text, **kwargs):
        """ Return a string after the renderization of the content
        
            :param text: The template 
            :param kwargs: The list of variables to be passed to the template
        """
        try:
            text = Template(text).render_unicode(**kwargs)
        except NameError:
            text = 'Error!! There is one or more variable in the template without its corresponding value'
        return text
        

class Makefile_FileType(FileType):
    """ Class to store makefile source code
    """
    def __init__(self):
        FileType.__init__(self, 'Makefile', '')
